package com.example.car.vm

import com.example.car.api.CarApiService
import com.example.car.entity.ParkingEntity
import com.example.car.model.CarRepository
import com.example.car.model.CarResultData
import com.example.common.view.vm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ParkingViewModel @Inject constructor(private val apiService : CarApiService) : BaseViewModel<CarRepository,CarResultData<List<ParkingEntity>>>() {
    fun getParking(areaId:Int){
        mViewModelScope.launch (mDispatcher){
            try {
                val result = apiService.getParking(areaId)
                mSuccessLiveData.postValue(result)
            } catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}